#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    editorLayout_ = new QGridLayout(ui->centralWidget);
    editorLayout_->setContentsMargins(2,2,2,2);

    textEditorsManager_ = new TextEditorsManager();
    editorLayout_->addWidget(textEditorsManager_);

    setupMenuBar();
    setupToolbars();

    textEditorsManager_->newFile();
}

MainWindow::~MainWindow()
{
    delete textEditorsManager_;
    delete editorLayout_;
    delete ui;
}

void MainWindow::closeEvent(QCloseEvent *)
{
    while(textEditorsManager_->count() > 0)
        textEditorsManager_->closeFile(0);
}

void MainWindow::setupMenuBar()
{
    menuBar_ = new MenuBar(textEditorsManager_, this);
    setMenuBar(menuBar_);
}

void MainWindow::setupToolbars()
{
    mainToolBar_ = new ToolBar("Tools", this);
    addToolBar(Qt::TopToolBarArea, mainToolBar_);

    mainToolBar_->setRole(ToolBar::MainToolBar);
}
